using Microsoft.AspNetCore.Mvc;
using BarrageGrab.GrabServices;


namespace BarrageGrab.Controllers
{
    [Route("api/wssurl")]
    [ApiController]
    public class ExampleController : ControllerBase
    {
        [HttpPost]
        public IActionResult PostData([FromBody] PostRequest request)
        {
            if (request == null)
            {
                return BadRequest("Invalid request");
            }

            // 创建服务的实例
            DouyinBarrageGrabService grabService = new DouyinBarrageGrabService();
            float userId = grabService.RcDecode(request.LiveCode);
            string liveId = "";
            string wssUrl = "";
            if (userId > 0)
            {
                // 启动服务，传入LiveId
                liveId = request.RoomId;  // 示例 liveId
                wssUrl = grabService?.Start(liveId);
                // 清理
                grabService?.Stop();
            }

            var response = new PostResponse
            {
                Code = 20000,
                Message = "Success",
                Data = new
                {
                    WssUrl = wssUrl
                }
            };

            return Ok(response);
        }
    }

    public class PostRequest
    {
        public string LiveCode { get; set; }
        public string RoomId { get; set; }
    }

    public class PostResponse
    {
        public int Code { get; set; }
        public string Message { get; set; }
        public object Data { get; set; }
    }
}
